var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/WFRollBackNodeWin.tsx
var WFRollBackNodeWin_exports = {};
__export(WFRollBackNodeWin_exports, {
  WFRollBackNodeWin: () => WFRollBackNodeWin,
  WFRollBackNodeWinFooter: () => WFRollBackNodeWinFooter,
  WFRollBackReason: () => WFRollBackReason
});
module.exports = __toCommonJS(WFRollBackNodeWin_exports);
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_service = require("./service");
var import_util2 = require("./util");
var Ids = {
  cbDyUser: "cbDyUser"
};
function DetailSkeleton({ height = 340 }) {
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: 8, height } }, /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { active: true }));
}
function findMatchingItems(arr1, arr2) {
  const result = [];
  arr2.forEach((item) => {
    const matchedItem = arr1.find((obj) => obj.value === item);
    if (matchedItem) {
      result.push(matchedItem);
    }
  });
  return result;
}
function RollBackPartNodeWin({ callback, taskId, toNodeId }) {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const tableRef = (0, import_util.useApi)();
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeOkHandler: async () => {
        var _a;
        const selectedData = tableRef.current.getApi().getSelectedData();
        if (selectedData.length === 0) {
          await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.hasNoRollBakNode);
          return;
        }
        callback({
          redoNodes: selectedData.map((d) => d.id),
          toNodeId
        });
        (_a = mCtx.ins) == null ? void 0 : _a.destroy();
      }
    });
  }, []);
  const memoInfo = (0, import_react.useMemo)(() => {
    return {
      columns: [
        { title: import_util2.NGLang.nodeName, dataIndex: "name", flex: 2 },
        { title: import_util2.NGLang.taskHisActor, dataIndex: "usersName", flex: 3 }
      ],
      request: async () => {
        const resp = await import_util.iup.request.get({
          url: "workflow3/workflow/GetRollBackRedoNodes",
          data: { taskid: taskId, toNodeId }
        });
        return resp.data || [];
      }
    };
  }, [taskId, toNodeId]);
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "5px 5px 0 5px", height: 340 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      request: memoInfo.request,
      checkbox: true,
      rowSelected: true,
      ref: tableRef,
      headerHeight: 32,
      rowHeight: 30,
      style: { border: "1px solid var(--border-color-split, #f0f0f0)" },
      columns: memoInfo.columns
    }
  ));
}
function RollBackNodeContent({ reader, callback, taskId }) {
  const rollBackInfo = reader().data;
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const tableRef = (0, import_util.useApi)();
  const msgTableRef = (0, import_util.useApi)();
  const rollModeRef = (0, import_util.useApi)();
  const [msgNodeList, setMsgNodeList] = (0, import_react.useState)([]);
  const [changeCount, setChangeCount] = (0, import_react.useState)(0);
  (0, import_react.useEffect)(() => {
    const copyNodeList = JSON.parse(JSON.stringify((rollBackInfo == null ? void 0 : rollBackInfo.nodeList) || []));
    copyNodeList.length && copyNodeList.map((v) => {
      v.checked = false;
      v.disabled = false;
    });
    setMsgNodeList([...copyNodeList]);
  }, []);
  const memoInfo = (0, import_react.useMemo)(() => {
    return {
      rollModeDisabled: false,
      options: findMatchingItems(
        [
          { value: "normal", label: "重新按顺序办理" },
          { value: "fast", label: "仅回退节点重新办理" }
        ],
        rollBackInfo.strategies
      ),
      columns: [
        { title: import_util2.NGLang.nodeName, dataIndex: "name", flex: 2 },
        { title: import_util2.NGLang.taskHisActor, dataIndex: "usersName", flex: 3 }
      ],
      columnsMsg: [
        { title: import_util2.NGLang.nodeName, dataIndex: "name", flex: 1 },
        { title: import_util2.NGLang.taskHisActor, dataIndex: "usersName", flex: 1 },
        {
          title: "消息接收对象",
          dataIndex: "checked",
          flex: 1,
          disabled({ row }) {
            return row.disabled;
          },
          editor: {
            xtype: "checkbox",
            checkedValue: true,
            unCheckedValue: false,
            antProps: {
              onClick: (e) => {
                var _a;
                setChangeCount(changeCount + 1);
                (_a = e.stopPropagation) == null ? void 0 : _a.call(e);
                const selectedData = tableRef.current.getApi().getSelectedData();
                if (selectedData.length === 0) {
                  (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.hasNoRollBakNode);
                  return;
                }
              }
            }
          }
        }
      ]
    };
  }, [rollBackInfo]);
  (0, import_react.useEffect)(() => {
    var _a;
    if ((_a = rollBackInfo.nodeList) == null ? void 0 : _a.length) {
      tableRef.current.getApi().setSelected(0);
      mCtx.ins.notify(!!rollBackInfo.nodeList[0].canDynamicUser, Ids.cbDyUser);
    }
    mCtx.ins.setApi({
      invokeOkHandler: async () => {
        var _a2, _b, _c;
        const isReceiver = rollBackInfo.allowSelectMessageReceiver;
        const selectedData = tableRef.current.getApi().getSelectedData()[0];
        const msgselectedData = isReceiver ? msgTableRef.current.getApi().getData() : [];
        const receivers = isReceiver ? msgselectedData.filter((v) => v.checked).map((el) => el.users).flat(Infinity) : selectedData.users;
        if (!selectedData) {
          await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.hasNoRollBakNode);
          return;
        }
        const rollMode = rollModeRef.current.getApi().getValue();
        const ProcessInitNode = (_a2 = rollBackInfo.nodeList) == null ? void 0 : _a2[rollBackInfo.nodeList.length - 1].id;
        if (rollMode === 2) {
          await (0, import_util2.wfModal)({
            title: import_util2.NGLang.rollBackPartNodeWinTitle,
            width: 600,
            content: /* @__PURE__ */ import_react.default.createElement(
              RollBackPartNodeWin,
              {
                toNodeId: selectedData.id,
                taskId,
                callback: (data) => {
                  var _a3;
                  callback(
                    {
                      ...data,
                      type: rollMode,
                      name: selectedData.name,
                      whetherProcessInitNode: ProcessInitNode === selectedData.id
                    },
                    false
                  );
                  (_a3 = mCtx.ins) == null ? void 0 : _a3.destroy();
                }
              }
            )
          });
        } else {
          callback(
            {
              toNodeId: selectedData.id,
              type: rollMode,
              redoNodes: [selectedData.id],
              name: selectedData.name,
              whetherProcessInitNode: ProcessInitNode === selectedData.id,
              receivers
              // 驳回事件消息传递对象
            },
            !!((_b = import_util.iup.getCmpApi(Ids.cbDyUser)) == null ? void 0 : _b.getValue())
          );
          (_c = mCtx.ins) == null ? void 0 : _c.destroy();
        }
      }
    });
  }, []);
  const hanleMsgTableData = (rowData) => {
    const list = (rollBackInfo == null ? void 0 : rollBackInfo.nodeList.length) && (rollBackInfo == null ? void 0 : rollBackInfo.nodeList.map((item) => {
      if ((item == null ? void 0 : item.id) === rowData.id) {
        item.checked = true;
        item.disabled = true;
      } else {
        item.checked = false;
        item.disabled = false;
      }
      return {
        ...item
      };
    })) || [];
    setMsgNodeList([...list]);
  };
  const onRow = (0, import_util.useRefCallback)((rowIndex, table) => {
    const row = table.getRow(rowIndex);
    if (changeCount === 0) {
      if (rollBackInfo.allowSelectMessageReceiver) {
        const selectedData = tableRef.current.getApi().getSelectedData();
        const rowData = selectedData.length && selectedData[0] || {};
        if (selectedData.length) {
          hanleMsgTableData(rowData);
        }
      }
    }
    return {
      onClick() {
        if (rollBackInfo.allowSelectMessageReceiver) {
          const selectedData = tableRef.current.getApi().getSelectedData();
          const rowData = selectedData.length && selectedData[0] || {};
          if (selectedData.length) {
            hanleMsgTableData(rowData);
          }
        }
        mCtx.ins.notify(!!row.canDynamicUser, Ids.cbDyUser);
      }
    };
  });
  return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, { height: 340, style: { padding: "0 5px" } }, /* @__PURE__ */ import_react.default.createElement("div", { style: { height: 36, display: "flex", alignItems: "center", paddingLeft: 6 } }, `${import_util2.NGLang.rollBackType}：`, /* @__PURE__ */ import_react.default.createElement(
    import_baseComponent.Select,
    {
      size: "small",
      style: { width: 180 },
      ref: rollModeRef,
      disabled: memoInfo.rollModeDisabled,
      options: memoInfo.options,
      defaultValue: rollBackInfo.defaultStrategy
    }
  )), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      dataSource: rollBackInfo.nodeList,
      ref: tableRef,
      rowSelected: true,
      headerHeight: 32,
      rowHeight: 30,
      onRow,
      style: { border: "1px solid var(--border-color-split, #f0f0f0)" },
      columns: memoInfo.columns
    }
  )), rollBackInfo.allowSelectMessageReceiver && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { style: { margin: "15px 0 10px", fontWeight: 600 } }, "驳回时消息接收对象："), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      dataSource: msgNodeList,
      ref: msgTableRef,
      headerHeight: 32,
      rowSelected: false,
      rowHeight: 30,
      style: { border: "1px solid var(--border-color-split, #f0f0f0)" },
      columns: memoInfo.columnsMsg
    }
  ))));
}
function WFRollBackNodeWin({ taskId, callback }) {
  const [dataReader] = (0, import_util.useAsyncSuspense)(import_service.getRollBackInfo, taskId, taskId);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Suspense, { fallback: /* @__PURE__ */ import_react.default.createElement(DetailSkeleton, null) }, /* @__PURE__ */ import_react.default.createElement(RollBackNodeContent, { reader: dataReader, callback, taskId }));
}
function WFRollBackNodeWinFooter() {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const [visible, setVisible] = (0, import_react.useState)(false);
  const [checked, setChecked] = (0, import_react.useState)(false);
  (0, import_react.useLayoutEffect)(() => {
    return mCtx.ins.subscribe((v) => {
      setVisible(v);
      setChecked(false);
    }, Ids.cbDyUser);
  }, []);
  if (visible) {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_baseComponent.Checkbox, { id: Ids.cbDyUser, checked, onChange: setChecked }, import_util2.NGLang.reSetUser), /* @__PURE__ */ import_react.default.createElement("span", { style: { flex: 1 } }));
  }
  return null;
}
function WFRollBackReason({ reasonData, callback }) {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const tableRef = (0, import_util.useApi)();
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeOkHandler: async () => {
        var _a;
        const selectedData = tableRef.current.getApi().getSelectedData()[0];
        if (!selectedData) {
          await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.choseRollBackReason);
          return;
        }
        callback(selectedData.phid);
        (_a = mCtx.ins) == null ? void 0 : _a.destroy();
      }
    });
  }, []);
  const memoInfo = (0, import_react.useMemo)(() => {
    return {
      columns: [
        { title: "ID", dataIndex: "phid", flex: 1 },
        { title: import_util2.NGLang.rollBackReason, dataIndex: "name", flex: 1, tooltip: true }
      ]
    };
  }, []);
  return /* @__PURE__ */ import_react.default.createElement("div", { style: { padding: "5px 5px 0 5px", height: 340 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      dataSource: reasonData,
      rowSelected: true,
      ref: tableRef,
      headerHeight: 32,
      rowHeight: 30,
      style: { border: "1px solid var(--border-color-split, #f0f0f0)" },
      columns: memoInfo.columns
    }
  ));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WFRollBackNodeWin,
  WFRollBackNodeWinFooter,
  WFRollBackReason
});
